Select
  Name,
  TegenrekeningNaam,
  count(TegenrekeningNaam) as Aantal
From
(Select
  Relation.Name,
  IIF(rb.Accounts > 1, Relation.Name + 'XXX' + rc.RelationAccountWithoutDots,
  Relation.Name) As TegenrekeningNaam
From
  ((((Select
    ra.FKRelation,
    Count(ra.RelationAccount) As Accounts
  From
    (Select
      [Transaction].FKRelation,
      [Transaction].RelationAccount
    From
      [Transaction]
    Where
      [Transaction].FKRelation <> 0 And
      [Transaction].RelationAccount <> ''
    Group By
      [Transaction].FKRelation, [Transaction].RelationAccount
    Order By
      [Transaction].FKRelation,
      [Transaction].RelationAccount) As ra
  Group By
    ra.FKRelation) As rb Right Join
  [Transaction] rc On rb.FKRelation = rc.FKRelation) Left Join
  Relation On rc.FKRelation = Relation.id) Inner Join
  Account On rc.FKAccount = Account.id) Left Join
  [Section] On rc.FKSection = [Section].id
Where
  rb.Accounts > 1
Order By
  TegenrekeningNaam)
Group By
  Name, TegenrekeningNaam
